package com.sbcb.script.rule;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RuleProcessor {
    @Autowired
    private RuleLoader ruleLoader;

    @Scheduled(fixedRate = 6000)
    public void startRules(){
        System.out.println("start rules");
        Order order = new Order();
        order.setLocation("Zhuhai, Guangdong, China");
        order.setPrice(123l);
        System.out.println(order);
        runRules(order);
    }

    public void runRules(Order order) {
        List<Rule> rules = ruleLoader.getRules();
        if (rules != null) {
            for (Rule rule : rules) {
                System.out.println(rule.process(order));
            }
        }
    }
}
